/**
 * 
 */

package com.chengyu.eyc.utils;

import java.util.Locale;

import cn.hutool.core.util.StrUtil;

/**
 * @author kevin
 *
 */
public class StringUtil extends StrUtil {

    /**
     * 下划线字符
     */
    public static final char UNDERLINE = '_';

    public static String camelToUnderline(String param) {
        if (isEmpty(param)) {
            return "";
        }
        int len = param.length();
        StringBuilder sb = new StringBuilder(len);
        for (int i = 0; i < len; i++) {
            char c = param.charAt(i);
            if (Character.isUpperCase(c) && i > 0) {
                sb.append(UNDERLINE);
            }
            sb.append(Character.toLowerCase(c));
        }
        return sb.toString();
    }

    public static String underlineToCamel(String param) {
        if (isEmpty(param)) {
            return "";
        }
        String temp = param.toLowerCase(Locale.getDefault());
        int len = temp.length();
        StringBuilder sb = new StringBuilder(len);
        for (int i = 0; i < len; i++) {
            char c = temp.charAt(i);
            if (c == UNDERLINE) {
                if (++i < len) {
                    sb.append(Character.toUpperCase(temp.charAt(i)));
                }
            } else {
                sb.append(c);
            }
        }
        return sb.toString();
    }

}
